#include<iostream>
#include<algorithm>
#include<fstream>
using namespace std;

int main()
{
	ofstream myfile;
	myfile.open("permutation.txt");
	const int N = 10;
	int A[N+2];
	int n;
	cout<<"enter a number n(n <= 10): ";
	while(1){
		cin>>n;
		if(n <= 10)break;
		else{cout<<"please enter a number n < 10."<<endl;}
	}
	for(int i = 0; i < n;  i++)
	{
		A[i] = i;
	}
	do
	{
		for(int i = 0; i < n; i++)
		{
			cout<<A[i]<<(i == n-1? '\n':' ');
			myfile<<A[i]<<(i == n-1 ? '\n' : ' ');
		}
	}while(next_permutation(A,A+n));
	myfile.close();
	return 0;
}
